package com.cslc.wechat.oauth.service.impl;

import java.util.Set;

import org.apache.log4j.Logger;

import com.cslc.wechat.common.bean.Clerk;
import com.cslc.wechat.common.bean.Terminal;
import com.cslc.wechat.common.dao.HibernateDao;
import com.cslc.wechat.oauth.service.OauthService;

public class OauthServiceImpl implements OauthService{
	private static Logger logger = Logger.getLogger(OauthServiceImpl.class);
	private HibernateDao hibernateDao;
	@Override
	public boolean isClerkBindTerminal(String openid) {
		//获取clerk对象
		String hql = "from Clerk c where c.openid = ?";
		String param = openid;
		Clerk clerk = (Clerk) hibernateDao.findUniqueObjByParam(hql, param);
		
		//clerk中不存在terminal，即未绑定任何终端
		if(null == clerk.getTerminals() || clerk.getTerminals().isEmpty())
			return false;
		else
			return true;
	}


	@Override
	public Set<Terminal> getClerkBindTerminals(String openid) {
		Set<Terminal> terminals = null;
		//获取clerk对象
		String hql = "from Clerk c where c.openid = ?";
		String param = openid;
		Clerk clerk = (Clerk) hibernateDao.findUniqueObjByParam(hql, param);
		terminals = clerk.getTerminals();
		return terminals;
	}
	
	public HibernateDao getHibernateDao() {
		return hibernateDao;
	}
	public void setHibernateDao(HibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}
}
